package com.siwei.mes.tgl.queue;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.siwei.mes.entity.tgl.*;
import com.siwei.mes.service.*;
import com.siwei.mes.tgl.init.TglProcessorInitializing;
import com.siwei.mes.tgl.service.SyncTglContractService;
import com.siwei.mes.tgl.service.SyncTglItemorderService;
import com.siwei.mes.tgl.service.SyncTglProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description: tgl队列处理数据
 * @Version: 1.0
 * @author: yangke
 * @date: 2023/12/30 21:09
 */
@Service
public class TglProcessorService {
    private static final Logger log = LoggerFactory.getLogger("tgl");
    @Resource
    private SyncTglContractService syncTglContractService;
    @Resource
    private SyncTglProjectService syncTglProjectService;
    @Resource
    private SyncTglItemorderService syncTglItemorderService;
    @Resource
    private TglRwdextraService tglRwdextraService;
    @Resource
    private TglTjlbyclService tglTjlbyclService;
    @Resource
    private TglTrwdphbService tglTrwdphbService;
    @Resource
    private TglTrwdphbyclService tglTrwdphbyclService;
    @Resource
    private TglTrwdService tglTrwdService;


    @Resource
    private TglProcessorInitializing tglProcessorInitializing;

    /**
     * 处理请求
     *
     * @param entityObject
     * @return
     */
    public boolean processRequest(Object entityObject) {
        try {
            if (entityObject instanceof TglContract) {
                TglContract entity = new ObjectMapper().convertValue(entityObject, TglContract.class);
                syncTglContractService.operateTglContract(entity);
            } else if (entityObject instanceof TglItemorder) {
                TglItemorder entity = new ObjectMapper().convertValue(entityObject, TglItemorder.class);
                return syncTglItemorderService.operateTglItemOrder(entity);
            } else if (entityObject instanceof TglProject) {
                TglProject entity = new ObjectMapper().convertValue(entityObject, TglProject.class);
                syncTglProjectService.operateTglProject(entity);
            } else if (entityObject instanceof TglRwdextra) {
                TglRwdextra entity = new ObjectMapper().convertValue(entityObject, TglRwdextra.class);
                tglRwdextraService.operateTglRwdextra(entity);
            } else if (entityObject instanceof TglTjlbycl) {
                TglTjlbycl entity = new ObjectMapper().convertValue(entityObject, TglTjlbycl.class);
                tglTjlbyclService.operateTglTjlbycl(entity);
            } else if (entityObject instanceof TglTrwd) {
                TglTrwd entity = new ObjectMapper().convertValue(entityObject, TglTrwd.class);
                tglTrwdService.operateTglTrwd(entity);
            } else if (entityObject instanceof TglTrwdphb) {
                TglTrwdphb entity = new ObjectMapper().convertValue(entityObject, TglTrwdphb.class);
                tglTrwdphbService.operateTglTrwdphb(entity);
            } else if (entityObject instanceof TglTrwdphbycl) {
                TglTrwdphbycl entity = new ObjectMapper().convertValue(entityObject, TglTrwdphbycl.class);
                tglTrwdphbyclService.operateTglTrwdphbycl(entity);
            } else {
                log.info("TGL新增或修改找不到对应类型,入参：{}", JSON.toJSONString(entityObject));
            }
        } catch (Exception e) {
            log.info("执行报错: " + e);
        }
        return true;
    }

    /**
     * 添加到队列
     * @param entity
     */
    public void submitRequest(Object entity) {
        tglProcessorInitializing.submitRequest(entity);
    }
}
